package devyouk.util.excel.listener;

import devyouk.util.excel.ColumnConfig;
import devyouk.util.excel.ExcelBuilder.OnCreateStyle;
import org.apache.poi.ss.usermodel.*;

public class DefaultHeadStyleListener implements OnCreateStyle {

    CellStyle style = null;
    @Override
    public CellStyle onCreate(Workbook workbook, ColumnConfig columnConfig) {
        if (style == null) {
            style = createDefaultStyle(workbook);
        }
        return style;
    }

    protected CellStyle createDefaultStyle(Workbook workbook) {
        CellStyle defaultStyle = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setColor(IndexedColors.WHITE.getIndex());
        font.setBold(true);
        defaultStyle.setFont(font);
        defaultStyle.setBorderBottom(BorderStyle.THIN); // 下边框
        defaultStyle.setBorderLeft(BorderStyle.THIN);// 左边框
        defaultStyle.setBorderTop(BorderStyle.THIN);// 上边框
        defaultStyle.setBorderRight(BorderStyle.THIN);// 右边框
        defaultStyle.setAlignment(HorizontalAlignment.CENTER);//居中显示
        defaultStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex()); // 单元格背景色
        defaultStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return defaultStyle;
    }
}
